package mylab.starters.mq.config.redis;

import lombok.RequiredArgsConstructor;
import mylab.starters.mq.config.MqAutoConfiguration;
import mylab.starters.mq.config.MqPropperties;
import mylab.starters.mq.impl.redis.RedisMqTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@AutoConfigureAfter(MqAutoConfiguration.class)
@ConditionalOnProperty(value = RedisMqAutoConfiguration.PREFIX, havingValue = "true")
public class RedisMqAutoConfiguration {

    static final public String PREFIX = MqPropperties.PREFIX + ".redis.enabled";

    final private MqPropperties mqPropperties;


    @Bean
    @ConditionalOnMissingBean
    public RedisMqTemplate template() {
        return new RedisMqTemplate(this.mqPropperties.getRedis());
    }
}
